package com.whfc.ms.api.fmam.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fmam.entity.dto.SyncFmamUnitDTO;
import com.whfc.fmam.service.FmamUnitService;
import com.whfc.fuum.entity.SysUser;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.util.List;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/11/11 15:09
 */
@RestController
@RequestMapping("ms/api/fmam")
public class FmamUnitController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @DubboReference(interfaceClass = FmamUnitService.class, version = "1.0.0")
    private FmamUnitService fmamUnitService;

    @GetMapping("unit/list")
    @RequiresAuthentication
    public Result getUnitList(@SessionAttribute(SessionAttr.MS_USER) SysUser loginUser) {
        logger.info("查询计量单位列表,loginUser:{}", loginUser.getUsername());
        List<SyncFmamUnitDTO> unitDTOList = fmamUnitService.getAllFmamUnitList();
        ListData listData = new ListData(unitDTOList);
        return ResultUtil.success(listData);
    }

}
